Skip to content

fix(terraphim-agent): resolve role shortnames, fix remote thesaurus, add LLM proxy fallback#726

Open
AlexMikhalev wants to merge 2 commits intomainfrom
fix/merge-conflicts
Open

fix(terraphim-agent): resolve role shortnames, fix remote thesaurus, add LLM proxy fallback#726
AlexMikhalev wants to merge 2 commits intomainfrom
fix/merge-conflicts

Conversation

@AlexMikhalev
Copy link
Copy Markdown
Contributor

Summary

This PR fixes several issues in the terraphim-agent crate to bring it to a working state:

Bug Fixes

  1. Role shortname resolution - --role flag in CLI and REPL was passing values directly to RoleName::new() instead of resolving via find_role_by_name_or_shortname(). Added resolve_role() methods to TuiService and ApiClient to properly resolve role shortnames.

  2. Remote thesaurus loading - read_url() function was implemented but never called for remote URLs. The Remote(_) branch returned a hardcoded error instead of fetching the data.

  3. Thesaurus format mismatch - Remote S3 file uses legacy flat format {"term": {"id": N, "nterm": "..."}} but code expected Thesaurus format {"name": "...", "data": {...}}. Added parse_thesaurus_json() helper to support both formats.

  4. Local KG fallback - Added fallback to local knowledge graph when remote automata_path fails.

  5. LLM fallback chain - Added proper fallback chain: Proxy → Ollama (when proxy disabled) for chat functionality when no explicit LLM config exists.

Features

  • CorrectionEvent for learnings - Added infrastructure for capturing and tracking user corrections to failed command learnings.

Code Quality

  • Separate 'proxy' feature - Created separate proxy feature in terraphim_service, made llm_router depend on it for cleaner feature gating.

  • Non-optional 'dirs' crate - Made dirs crate non-optional since it's used in always-compiled modules (onboarding, learnings).

Testing

All tests pass:

  • selected_role_tests: 8/8 passing
  • Tests updated to handle proxy connection errors gracefully

Files Changed

  • crates/terraphim_agent/src/service.rs - Added resolve_role() to TuiService
  • crates/terraphim_agent/src/client.rs - Added resolve_role() for server mode
  • crates/terraphim_agent/src/main.rs - Updated all CLI subcommands to use resolve_role()
  • crates/terraphim_agent/src/repl/handler.rs - Updated REPL search to resolve shortnames
  • crates/terraphim_agent/Cargo.toml - Made dirs non-optional
  • crates/terraphim_automata/src/lib.rs - Fixed remote loading, added legacy format parsing
  • crates/terraphim_config/src/lib.rs - Added local KG fallback, added default LLM config to roles
  • crates/terraphim_service/src/llm.rs - Added proxy fallback, reorganized fallback chain
  • crates/terraphim_service/src/llm/proxy_client.rs - Improved error message
  • crates/terraphim_service/Cargo.toml - Added proxy feature
  • crates/terraphim_agent/tests/selected_role_tests.rs - Updated test assertions

Alex added 2 commits March 26, 2026 09:40
- Resolve conflicts in learnings/mod.rs (kept necessary exports)
- Resolve conflicts in main.rs (removed unused imports)
- Fix formatting with cargo fmt
- Clean up unused imports per clippy warnings

All pre-commit checks pass:
- Formatting: clean
- Clippy: no warnings
- Build: successful
- Tests: 148 passed

Note: Test fixtures contain example AWS keys for testing secret redaction
…add LLM proxy fallback

- Add resolve_role() to TuiService and ApiClient to resolve role shortnames via find_role_by_name_or_shortname()
- Fix remote thesaurus loading - read_url() was never called for Remote URLs
- Add parse_thesaurus_json() to support both new Thesaurus format and legacy flat format
- Add local KG fallback when remote automata_path fails
- Add LLM fallback chain: Proxy -> Ollama (when proxy disabled)
- Create separate 'proxy' feature in terraphim_service, llm_router depends on it
- Make 'dirs' crate non-optional (was used in always-compiled modules)
- Update tests to handle proxy connection errors gracefully
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant